<?php

namespace App\Http\Controllers\Api\v1;

use App\Http\Resources\BannerResource;
use App\Models\Banner;
use Illuminate\Http\Request;

class BannerController extends Controller
{
    public function index(request $request)
    {
        $request->validate([
           'type' => 'required|in:home,welfare_goods'
        ]);
        $location = $request->get('type','home');
        switch ($location) {
            case 'home':
                $location = Banner::HOME;
                break;
            case 'welfare_goods':
                $location = Banner::WELFARE_GOODS;
                break;
        }
        $banner = Banner::getBanner($location, 0);
         return $this->success(BannerResource::collection($banner));
    }
}
